package com.atguigu.gulimall.order.config;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author ShiJieLin
 * @Date 2022/4/19 22:37
 * @Version 1.0
 */
@Configuration
@EnableConfigurationProperties(MyThreadProperties.class)
public class MyThreadConfig {

    /** 创建一个线程池
     * @return
     */
    @Bean
    public ThreadPoolExecutor threadPoolExecutor(MyThreadProperties pro){

        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(pro.getCorePoolSize(), pro.getMaximumPoolSize(),
                pro.getKeepAliveTime(), TimeUnit.SECONDS,
                new LinkedBlockingQueue<>());

        return poolExecutor;
    }

}
